package com.example.q_kang.hhh.setting;

import com.example.q_kang.hhh.api.JsonCallBack;
import com.hjq.toast.ToastUtils;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.sskj.base.BasePresenter;
import com.example.q_kang.hhh.setting.SingleFragment;
import com.sskj.base.api.Constant;
import com.sskj.base.base.HttpData;
import com.sskj.base.bean.MasterUpBean;


/**
 * @author Hey
 * Create at  2019/04/18
 */
class SinglePresenter extends BasePresenter<SingleFragment> {

    public void getOrdersMoneys() {
        httpService.getOrderMoneys()
                .tag(this)
                .execute(new JsonCallBack<HttpData<MasterUpBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<MasterUpBean>> response) {
                        HttpData<MasterUpBean> body = response.body();
                        if (body.getStatus() == Constant.OK) {
                            mView.updataMaster(body.getData());
                        }

                    }

                    @Override
                    public void onStart(Request<HttpData<MasterUpBean>, ? extends Request> request) {
                        super.onStart(request);
                        mView.showLoading();
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        mView.hideLoading();
                    }
                });

    }

    public void masterChage(String price) {
        httpService.masterChange(price)
                .tag(this)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtils.show(body.getMsg());
                        if (body.getStatus() == Constant.OK) {
                            mView.getActivity().finish();
                        }
                    }

                    @Override
                    public void onStart(Request<HttpData, ? extends Request> request) {
                        super.onStart(request);
                        mView.showLoading();
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        mView.hideLoading();
                    }
                });
    }


}
